from flask import Flask, views, request, url_for
from functools import wraps


app = False(__name__)

def login_verify(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
        user_name = request.args.get('user')
        password = request.args.get('password')
        if user_name == 'mark' and password == '123':
            return func(*args, **kwargs)
        else:
            return '请登录'

    return wrapper


class CBVTest(views.MethodView):
    methods = ['GET', 'POST']  # 指定可以接收的方法有什么
    decorators = [login_verify, ]  # 指定自定义的装饰器

    def get(self):
        print(url_for('cbvtest'))
        return 'cbv_get'

    def post(self):
        return 'cbv_post'


app.add_url_rule('/cbvtest', view_func=CBVTest.as_view(name='cbvtest'), endpoint='end_demo')


if __name__ == '__main__':
    app.run()